From 1a50cc02abe0b65c066579dd9635ca3f1f2ab924 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 31 Aug 2016 21:01:36 -0700 Subject: [PATCH] Macros 1.1 --- src/cargo/core/manifest.rs | 6 +++++- src/cargo/util/toml.rs | 18 +++++++++++++++++- src/doc/manifest.md | 11 ++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index a0e745057..827008b8b 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -61,6 +61,7 @@ pub enum LibKind { Lib, Rlib, Dylib, + RustcMacro, Other(String), } @@ -70,6 +71,7 @@ impl LibKind { "lib" => LibKind::Lib, "rlib" => LibKind::Rlib, "dylib" => LibKind::Dylib, + "rustc-macro" => LibKind::RustcMacro, s => LibKind::Other(s.to_string()), } } @@ -80,6 +82,7 @@ impl LibKind { LibKind::Lib => "lib", LibKind::Rlib => "rlib", LibKind::Dylib => "dylib", + LibKind::RustcMacro => "rustc-macro", LibKind::Other(ref s) => s, } } @@ -88,7 +91,8 @@ impl LibKind { match *self { LibKind::Lib | LibKind::Rlib | - LibKind::Dylib => true, + LibKind::Dylib | + LibKind::RustcMacro => true, LibKind::Other(..) => false, } } diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 0c138e648..811e58b49 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -444,6 +444,7 @@ impl TomlManifest { let lib = match self.lib { Some(ref lib) => { try!(lib.validate_library_name()); + try!(lib.validate_crate_type()); Some( TomlTarget { name: lib.name.clone().or(Some(project.name.clone())), @@ -900,6 +901,7 @@ struct TomlTarget { bench: Option, doc: Option, plugin: Option, + rustc_macro: Option, harness: Option, } @@ -928,6 +930,7 @@ impl TomlTarget { bench: None, doc: None, plugin: None, + rustc_macro: None, harness: None, } } @@ -1006,6 +1009,14 @@ impl TomlTarget { None => Err(human("bench target bench.name is required".to_string())) } } + + fn validate_crate_type(&self) -> CargoResult<()> { + if self.plugin == Some(true) && self.rustc_macro == Some(true) { + Err(human("lib.plugin and lib.rustc-macro cannot both be true".to_string())) + } else { + Ok(()) + } + } } impl PathValue { @@ -1040,7 +1051,11 @@ fn normalize(lib: &Option, .set_doctest(toml.doctest.unwrap_or(t2.doctested())) .set_benched(toml.bench.unwrap_or(t2.benched())) .set_harness(toml.harness.unwrap_or(t2.harness())) - .set_for_host(toml.plugin.unwrap_or(t2.for_host())); + .set_for_host(match (toml.plugin, toml.rustc_macro) { + (None, None) => t2.for_host(), + (Some(true), _) | (_, Some(true)) => true, + _ => false, + }); } fn lib_target(dst: &mut Vec, @@ -1053,6 +1068,7 @@ fn normalize(lib: &Option, Some(kinds) => kinds.iter().map(|s| LibKind::from_str(s)).collect(), None => { vec![ if l.plugin == Some(true) {LibKind::Dylib} + else if l.rustc_macro == Some(true) {LibKind::RustcMacro} else {LibKind::Lib} ] } }; diff --git a/src/doc/manifest.md b/src/doc/manifest.md index 675841784..086d214d8 100644 --- a/src/doc/manifest.md +++ b/src/doc/manifest.md @@ -508,6 +508,10 @@ doc = true # for Cargo to correctly compile it and make it available for all dependencies. plugin = false +# If the target is meant to be a "macros 1.1" procedural macro, this field must +# be set to true. +rustc-macro = false + # If set to false, `cargo test` will omit the `--test` flag to rustc, which # stops it from generating a test harness. This is useful when the binary being # built manages the test runner itself. @@ -527,9 +531,10 @@ name = "..." crate-type = ["dylib"] # could be `staticlib` as well ``` -The available options are `dylib`, `rlib`, `staticlib`, and `cdylib`. You -should only use this option in a project. Cargo will always compile packages -(dependencies) based on the requirements of the project that includes them. +The available options are `dylib`, `rlib`, `staticlib`, `cdylib`, and +`rustc-macro`. You should only use this option in a project. Cargo will always +compile packages (dependencies) based on the requirements of the project that +includes them. You can read more about the different crate types in the [Rust Reference Manual](https://doc.rust-lang.org/reference.html#linkage) -- 2.30.2